const app = getApp()
import {
  GetRules,
  ListByYear
} from '../../../config/api'
import util from '../../../utils/util'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    date: '',
    rules: [], //加分规则
    time: '', //当前系统年份
    redlist: [], //年份筛选的红名单数据
    pid: 0, //父id
    title: ''

  },
  /**
   * 选择年份
   */
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    let that = this;
    that.setData({
      date: e.detail.value
    });
    let params = {
      year: parseInt(e.detail.value),
      pid: that.data.pid,
      vollege_id: app.globalData.vollege_id
    };
    //加载当前系统年份的菜单
    util.apiRequest(ListByYear, params, null).then(r => {
      console.log('数据：', r.data.data.data);
      that.setData({
        redlist: r.data.data.data,
      });

    });

  },
  /**
   * 点击跳转到我要上红榜
   */
  ToRed: function() {
    console.log('点击我要上红榜！');
    wx.navigateTo({
      url: "/pages/integralBank/onRedList/onRedList",
    });
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('pid:', options.id);
    console.log('title:', options.title);

    //获取当当前系统时间
    let currentYear = new Date().getFullYear() + '';
    let that = this;
    that.setData({
      date: currentYear,
      time: currentYear,
      pid: options.id,
      title: options.title

    });

    util.apiRequest(GetRules, {
      id: that.data.pid
    }, null).then(r => {
      console.log('加分规则', r.data.data);

      var str = r.data.data.desc.replace(/\n/g, "|-&");
      var rules = str.split("|-&");
      console.log('转换后', rules)

      that.setData({
        rules: rules,
      });
    });

    let params = {
      year: currentYear,
      pid: options.id,
      vollege_id: app.globalData.vollege_id
    };
    //加载当前系统年份的菜单
    util.apiRequest(ListByYear, params, null).then(r => {
      console.log('获取到当前系统年份的筛选数据：', r.data.data.data);
      that.setData({
        redlist: r.data.data.data,
      });

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})